/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nsgf.library.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

import androidx.recyclerview.widget.RecyclerView;

import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;
import com.nsgf.library.R;
import com.nsgf.library.data.bean.ClockInBean;
import com.nsgf.library.databinding.ItemNsgfHomeVideoListBinding;

/**
 * Create by GC at 24/11/19
 */
public class ClockInfoListAdapter extends SimpleDataBindingAdapter<ClockInBean.DataBean, ItemNsgfHomeVideoListBinding> {

    public ClockInfoListAdapter(Context context) {
        super(context, R.layout.item_nsgf_home_video_list, DiffUtils.getInstance().getClockInInfoItemCallback());

    }

    @Override
    protected void onBindItem(ItemNsgfHomeVideoListBinding binding, ClockInBean.DataBean item, RecyclerView.ViewHolder holder) {

        CheckWorkAttendanceListAdapter adapter = new CheckWorkAttendanceListAdapter(mContext);
        binding.setAdapter(adapter);
        binding.recyclerViewLate.setAdapter(adapter);


        binding.setVm(item);
        adapter.notifyDataSetChanged();

        final boolean[] rotation = {false};
        binding.llItemVideoTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 获取当前的旋转角度
                float currentRotation = binding.ivItemTitleUp.getRotation();

                // 计算下一个旋转角度
                float nextRotation = currentRotation + 90;

                // 创建旋转动画
                RotateAnimation rotateAnimation = new RotateAnimation(currentRotation, nextRotation,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnimation.setDuration(100); // 设置动画持续时间（例如100毫秒）
                rotateAnimation.setFillAfter(true); // 设置动画结束后保持结束状态

                // 设置动画监听器，如果需要
                rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        // 动画开始时的处理
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        // 动画结束时的处理
                        if (rotation[0]) {
                            rotation[0] = false;
                            binding.recyclerViewLate.setVisibility(View.GONE);
                        } else {
                            rotation[0] = true;
                            binding.recyclerViewLate.setVisibility(View.VISIBLE);
                        }


                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                        // 动画重复播放时的处理
                    }
                });
                // 启动动画
                binding.ivItemTitleUp.startAnimation(rotateAnimation);
                // 更新当前的旋转角度
                binding.ivItemTitleUp.setRotation(nextRotation);

            }
        });

    }

}
